#!/usr/bin/env python
# -*- coding:utf-8 -*-

# 生成列表

def test1():
    '''+
    '''
    l = []
    for i in range(1000):
        l = l + [i]

def test2():
    '''append
    '''
    l = []
    for i in range(1000):
        l.append(i)

def test3():
    '''列表生成器
    '''
    l = [i for i in range(1000)]

def test4():
    '''列表构造函数
    '''
    l = list(range(1000))

import timeit

# t1 = timeit.Timer("test1()", "from __main__ import test1")
# print("concat ",t1.timeit(number=1000), "milliseconds")
# t2 = timeit.Timer("test2()", "from __main__ import test2")
# print("append ",t2.timeit(number=1000), "milliseconds")
# t3 = timeit.Timer("test3()", "from __main__ import test3")
# print("comprehension ",t3.timeit(number=1000), "milliseconds")
# t4 = timeit.Timer("test4()", "from __main__ import test4")
# print("list range ",t4.timeit(number=1000), "milliseconds")

def test5():
    '''构造200万元素的列表
    '''
    l = list(range(2000000))

# t5 = timeit.Timer("test5()", "from __main__ import test5")
# print "list range", t5.timeit(number=1000), "milliseconds"


popzero = timeit.Timer("x.pop(0)",
"from __main__ import x")
popend = timeit.Timer("x.pop()",
"from __main__ import x")
x = list(range(2000000))
print popzero.timeit(number=1000)

x = list(range(2000000))
print popend.timeit(number=1000)